<?php
//phan trang
function showpage($page, $totalpage, $pagesize, $keygetdata='')
{
	// mod 연산(%) 을 이용해 페이지를 구한다.
	$temp = $page - ($page % $pagesize);
	if($temp != 0)
	$cpage = $temp / $pagesize;
	else
	$cpage = 0;
	// prev시 알고리즘상 앞페이지로 안간다.
	if($page % $pagesize == 0) $cpage = $cpage - 1;
	$page_starter = $cpage * $pagesize;
	$page_ender = ($cpage * $pagesize) + $pagesize;

	$r_value = array();
	if ($page_starter != 0 )
	$r_value["prev"] = "<a href=$PHP_SELF?page=$page_starter$keygetdata>[prev]</a>";

	for($i=$page_starter+1; $i<=$page_ender; $i++)
	{
		if ($i > $totalpage)
		continue;
		else if ($i == $page)
		$r_value[$i] = isset($r_value[$i]) ? $r_value[$i] . " <b>$i</b> " : " <b>$i</b> ";
		else
		$r_value[$page] .=  " <a href=$PHP_SELF?page=$i$keygetdata>[$i]</a> ";
	}

	if ($page_ender < $totalpage)
	$r_value["next"] =  "<a href=$PHP_SELF?page=".($page_ender+1)."$keygetdata>[next]</a>";

	return $r_value;
}

#<select> of product category
function select_category($name, $value, $DB)
{   
	$select = "<select name='$name'>";	#
	$query = "SELECT name, id FROM product_category WHERE parents<>0 ORDER BY `order`";
	
	$DB->QueryRow($query);
	$count1 = $DB->rows;	 
	for($i=0; $i<$count1; $i++)
	{
		$product_category = $DB->Fetch($i);		
		$select .= "<option ";
		if ($product_category['id'] == $value)
		  $select .= "selected='selected' ";
		
		$select .= "value='$product_category[id]'";
		$select .= ">$product_category[name]</option>";
	}
	$select .= "</select>";	
	echo $select; 
}
/*
<select name="cat_id">      
        <?php
        #
        $query = "SELECT name, id FROM product_category WHERE parents<>0 ORDER BY `order`"; 
        $DB->QueryRow($query);
        $count1 = $DB->rows;
        for($i=0; $i<$count1; $i++)
        {
            $product_category = $DB->Fetch($i);
            #echo $product_category[id];
        ?>
            <option <?php if ($product_category[id] == ) echo ("selected='selected'");?> value="<?php echo ($product_category[id])?>"><?php echo (">".$product_category[name])?></option>
        <?php       
        }   
        ?>

        </select>
*/
?>